﻿@page "/Fin/OtherIncome/Details"
@using nERP.ViewModel.Fin.OtherIncomeVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Tab IsBorderCard="true">
            <TabItem Text="@WtmBlazor.Localizer["_Admin.BasicInfo"]">
                <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
                    <Display @bind-Value="@Model.Entity.OtherIncomeCode" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.CustomerId" ShowLabel="true" Lookup="AllCustomers" />
                    <Display @bind-Value="@Model.Entity.MakeUserId" ShowLabel="true" Lookup="AllMakeUsers" />
                    <Display @bind-Value="@Model.Entity.InvoicesDate" ShowLabel="true" FormatString="yyyy-MM-dd" />
                    <Display @bind-Value="@Model.Entity.SettlementAccountId" ShowLabel="true" Lookup="AllSettlementAccounts" />
                    <Display @bind-Value="@Model.Entity.IncomeTypeId" ShowLabel="true" Lookup="AllIncomeTypes" />
                    <Display @bind-Value="@Model.Entity.TotalPrice" ShowLabel="true" FormatString="0.##" />
                    <Display @bind-Value="@Model.Entity.Status" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.Remark" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.CreateTime" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.UpdateTime" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.CreateBy" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.UpdateBy" ShowLabel="true" />
                    <WTUploadImage @bind-Value="@Model.Entity.InvoicesImage" IsDisabled="true" thumb-width="128" />
                </Row>

            </TabItem>

            <TabItem Text="@WtmBlazor.Localizer["Page.审批信息"]">
                <WTApproveHistory Model="@Model" />
            </TabItem>

        </Tab>

        <div class="modal-footer table-modal-footer">
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private OtherIncomeVM Model = new OtherIncomeVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Fin/OtherIncome/Edit", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllCustomers = new List<SelectedItem>();
    private List<SelectedItem> AllMakeUsers = new List<SelectedItem>();
    private List<SelectedItem> AllSettlementAccounts = new List<SelectedItem>();
    private List<SelectedItem> AllIncomeTypes = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllCustomers = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherIncome/GetCustomers");
        AllCustomers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllMakeUsers = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherIncome/GetFrameworkUsers");
        AllMakeUsers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSettlementAccounts = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherIncome/GetSettlementAccounts");
        AllSettlementAccounts.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllIncomeTypes = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherIncome/GetDicFields其他收入类别");
        AllIncomeTypes.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<OtherIncomeVM>($"/api/Fin/OtherIncome/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
